package ch.subgate.chessvisualizationtrainer.utils;

import java.util.ArrayList;
import java.util.Random;

public class ChessProblemCollection {
	
	private String mType;
	private String mQuestion;
	private String mAnswerA;
	private String mAnswerB;
	
	private ArrayList<ChessProblem> mProblems;
	
	public ChessProblemCollection(
			String type,
			String question,
			String answerA,
			String answerB) {
		mType = type;
		mQuestion = question;
		mAnswerA = answerA;
		mAnswerB = answerB;
		
		mProblems = new ArrayList<ChessProblem>();
	}
	
	public boolean addChessProblem(ChessProblem problem) {
		if (problem == null) return false;
		
		if (
				problem.getSolution().equalsIgnoreCase(mAnswerA) ||
				problem.getSolution().equalsIgnoreCase(mAnswerB)) {
			mProblems.add(problem);
			return true;
		}
		
		return false;
	}
	
	public ChessProblem getRandomProblem() {
		if (mProblems.isEmpty()) {
			return null;
		}
		
		Random r = new Random();
		
		int i = r.nextInt(mProblems.size());
		
		return mProblems.get(i);
	}
	
	public String getType() {
		return mType;
	}
	
	public String getQuestion() {
		return mQuestion;
	}
	
	public String getAnswerA() {
		return mAnswerA;
	}
	
	public String getAnswerB() {
		return mAnswerB;
	}

}
